<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Android,Note," />





  <link rel="alternate" href="/atom.xml" title="GrantonZhuang's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="这篇文章为读书笔记，主要内容是 ContentProvider 的启动过程。">
<meta property="og:type" content="article">
<meta property="og:title" content="ContentProvider的启动过程">
<meta property="og:url" content="https://grantonzhuang.github.io/2016/09/04/ContentProvider的启动过程/index.html">
<meta property="og:site_name" content="GrantonZhuang's Blog">
<meta property="og:description" content="这篇文章为读书笔记，主要内容是 ContentProvider 的启动过程。">
<meta property="og:updated_time" content="2016-09-04T10:01:58.301Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ContentProvider的启动过程">
<meta name="twitter:description" content="这篇文章为读书笔记，主要内容是 ContentProvider 的启动过程。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="https://grantonzhuang.github.io/2016/09/04/ContentProvider的启动过程/"/>

  <title> ContentProvider的启动过程 | GrantonZhuang's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">GrantonZhuang's Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle"></p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                ContentProvider的启动过程
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-04T17:48:47+08:00" content="2016-09-04">
              2016-09-04
            </time>
          </span>

          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>这篇文章为读书笔记，主要内容是 ContentProvider 的启动过程。</p>
<a id="more"></a>
<h2 id="方法入口"><a href="#方法入口" class="headerlink" title="方法入口"></a>方法入口</h2><h3 id="进程启动"><a href="#进程启动" class="headerlink" title="进程启动"></a>进程启动</h3><p>AMS 启动一个进程的时候调用了 <code>startProcessLocked()</code> 方法，在这个方法内有一段代码。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">if</span> (entryPoint == <span class="keyword">null</span>) entryPoint = <span class="string">"android.app.ActivityThread"</span>;</div><div class="line">Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, <span class="string">"Start proc: "</span> +</div><div class="line">        app.processName);</div><div class="line">checkTime(startTime, <span class="string">"startProcess: asking zygote to start proc"</span>);</div><div class="line">Process.ProcessStartResult startResult = Process.start(entryPoint,</div><div class="line">        app.processName, uid, uid, gids, debugFlags, mountExternal,</div><div class="line">        app.info.targetSdkVersion, app.info.seinfo, requiredAbi, instructionSet,</div><div class="line">        app.info.dataDir, entryPointArgs);</div></pre></td></tr></table></figure>
<p>这段代码中调用了 <code>Process#start()</code> 方法，加载了类 <code>ActivityThread</code>，我们知道 java 程序的入口是静态的 main 方法，这在 Android 中也一样。</p>
<h3 id="ActivityThread-main"><a href="#ActivityThread-main" class="headerlink" title="ActivityThread#main()"></a><code>ActivityThread#main()</code></h3><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</div><div class="line">    <span class="comment">// ...</span></div><div class="line"></div><div class="line">    ActivityThread thread = <span class="keyword">new</span> ActivityThread();</div><div class="line">    thread.attach(<span class="keyword">false</span>);</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (sMainThreadHandler == <span class="keyword">null</span>) &#123;</div><div class="line">        sMainThreadHandler = thread.getHandler();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">false</span>) &#123;</div><div class="line">        Looper.myLooper().setMessageLogging(<span class="keyword">new</span></div><div class="line">                LogPrinter(Log.DEBUG, <span class="string">"ActivityThread"</span>));</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">// End of event ActivityThreadMain.</span></div><div class="line">    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);</div><div class="line">    <span class="comment">// 开始消息循环</span></div><div class="line">    Looper.loop();</div><div class="line"></div><div class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"Main thread loop unexpectedly exited"</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="ActivityThread-attach"><a href="#ActivityThread-attach" class="headerlink" title="ActivityThread#attach()"></a><code>ActivityThread#attach()</code></h3><p>在 ActivityThread 的 attach 方法中，调用了 <code>IActivityManager#attachApplication()</code> 将 AMS 和 Application 绑定起来.</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">final</span> IActivityManager mgr = ActivityManagerNative.getDefault();</div><div class="line"><span class="keyword">try</span> &#123;</div><div class="line">    mgr.attachApplication(mAppThread);</div><div class="line">&#125; <span class="keyword">catch</span> (RemoteException ex) &#123;</div><div class="line">    <span class="comment">// Ignore</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li><p>AMS 的 <code>attachApplication()</code> 方法实际调用了 <code>attachApplicationLocked()</code> 方法</p>
</li>
<li><p>继而调用了 <code>IApplicationThread#bindApplicaion()</code>，</p>
</li>
<li><p>接着通过发送一个 Message 对象到内部的 Handler 的子类 H，</p>
</li>
<li><p>调用了 <code>ActivityThread#handleBindApplication()</code>，在这个方法里完成了 Application 和 ContentProvider 的创建。</p>
</li>
</ul>
<h2 id="handleBindApplication-方法的详情"><a href="#handleBindApplication-方法的详情" class="headerlink" title="handleBindApplication() 方法的详情"></a>handleBindApplication() 方法的详情</h2><h3 id="创建-ContextImpl-和-Instrumention"><a href="#创建-ContextImpl-和-Instrumention" class="headerlink" title="创建 ContextImpl 和 Instrumention"></a>创建 ContextImpl 和 Instrumention</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">ContextImpl instrContext = ContextImpl.createAppContext(<span class="keyword">this</span>, pi);</div><div class="line"><span class="keyword">try</span> &#123;</div><div class="line">    java.lang.ClassLoader cl = instrContext.getClassLoader();</div><div class="line">    mInstrumentation = (Instrumentation)</div><div class="line">        cl.loadClass(data.instrumentationName.getClassName()).newInstance();</div><div class="line">&#125; <span class="keyword">catch</span> (Exception e) &#123;</div><div class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(</div><div class="line">        <span class="string">"Unable to instantiate instrumentation "</span></div><div class="line">        + data.instrumentationName + <span class="string">": "</span> + e.toString(), e);</div><div class="line">&#125;</div><div class="line"></div><div class="line">mInstrumentation.init(<span class="keyword">this</span>, instrContext, appContext,</div><div class="line">   <span class="keyword">new</span> ComponentName(ii.packageName, ii.name), data.instrumentationWatcher,</div><div class="line">   data.instrumentationUiAutomationConnection);</div></pre></td></tr></table></figure>
<h3 id="创建-Application"><a href="#创建-Application" class="headerlink" title="创建 Application"></a>创建 Application</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">Application app = data.info.makeApplication(data.restrictedBackupMode, <span class="keyword">null</span>);</div><div class="line">mInitialApplication = app;</div></pre></td></tr></table></figure>
<h3 id="启动当前进程的-ContentProvider-并且调用-onCreate-方法"><a href="#启动当前进程的-ContentProvider-并且调用-onCreate-方法" class="headerlink" title="启动当前进程的 ContentProvider 并且调用 onCreate() 方法"></a>启动当前进程的 ContentProvider 并且调用 onCreate() 方法</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">List&lt;ProviderInfo&gt; providers = data.providers;</div><div class="line"><span class="keyword">if</span> (providers != <span class="keyword">null</span>) &#123;</div><div class="line">    installContentProviders(app, providers);</div><div class="line">    <span class="comment">// For process that contains content providers, we want to</span></div><div class="line">    <span class="comment">// ensure that the JIT is enabled "at some point".</span></div><div class="line">    mH.sendEmptyMessageDelayed(H.ENABLE_JIT, <span class="number">10</span>*<span class="number">1000</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><code>installContentProviders()</code> 方法的详情</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">installContentProviders</span><span class="params">(</span></span></div><div class="line">    Context context, List&lt;ProviderInfo&gt; providers) &#123;</div><div class="line">    <span class="keyword">final</span> ArrayList&lt;IActivityManager.ContentProviderHolder&gt; results =</div><div class="line">        <span class="keyword">new</span> ArrayList&lt;IActivityManager.ContentProviderHolder&gt;();</div><div class="line">    <span class="comment">// 遍历 ProviderInfo 对象</span></div><div class="line">    <span class="keyword">for</span> (ProviderInfo cpi : providers) &#123;</div><div class="line">        <span class="keyword">if</span> (DEBUG_PROVIDER) &#123;</div><div class="line">            StringBuilder buf = <span class="keyword">new</span> StringBuilder(<span class="number">128</span>);</div><div class="line">            buf.append(<span class="string">"Pub "</span>);</div><div class="line">            buf.append(cpi.authority);</div><div class="line">            buf.append(<span class="string">": "</span>);</div><div class="line">            buf.append(cpi.name);</div><div class="line">            Log.i(TAG, buf.toString());</div><div class="line">        &#125;</div><div class="line">        <span class="comment">// 启动这些 Provider</span></div><div class="line">        IActivityManager.ContentProviderHolder cph = installProvider(context, <span class="keyword">null</span>, cpi,</div><div class="line">                <span class="keyword">false</span> <span class="comment">/*noisy*/</span>, <span class="keyword">true</span> <span class="comment">/*noReleaseNeeded*/</span>, <span class="keyword">true</span> <span class="comment">/*stable*/</span>);</div><div class="line">        <span class="keyword">if</span> (cph != <span class="keyword">null</span>) &#123;</div><div class="line">            cph.noReleaseNeeded = <span class="keyword">true</span>;</div><div class="line">            results.add(cph);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    <span class="comment">// 发布到 AMS 中</span></div><div class="line">    <span class="keyword">try</span> &#123;</div><div class="line">        ActivityManagerNative.getDefault().publishContentProviders(</div><div class="line">            getApplicationThread(), results);</div><div class="line">    &#125; <span class="keyword">catch</span> (RemoteException ex) &#123;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><code>installProvider()</code> 方法的详情，通过类加载器加载了相应的 ContentProvider</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">final</span> java.lang.ClassLoader cl = c.getClassLoader();</div><div class="line">localProvider = (ContentProvider)cl.</div><div class="line">    loadClass(info.name).newInstance();</div><div class="line">provider = localProvider.getIContentProvider();</div><div class="line"><span class="keyword">if</span> (provider == <span class="keyword">null</span>) &#123;</div><div class="line">    Slog.e(TAG, <span class="string">"Failed to instantiate class "</span> +</div><div class="line">          info.name + <span class="string">" from sourceDir "</span> +</div><div class="line">          info.applicationInfo.sourceDir);</div><div class="line">    <span class="keyword">return</span> <span class="keyword">null</span>;</div><div class="line">&#125;</div><div class="line"><span class="keyword">if</span> (DEBUG_PROVIDER) Slog.v(</div><div class="line">    TAG, <span class="string">"Instantiating local provider "</span> + info.name);</div><div class="line"><span class="comment">// XXX Need to create the correct context for this provider.</span></div><div class="line">localProvider.attachInfo(c, info);</div></pre></td></tr></table></figure>
<p><code>ContentProvider#attachInfo()</code> 方法的详情，在这里设置了 ContentProvider 的编写者在 manifest 文件中设置的一些属性，并且调用了 <code>onCreate()</code> 方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">attachInfo</span><span class="params">(Context context, ProviderInfo info, <span class="keyword">boolean</span> testing)</span> </span>&#123;</div><div class="line">    mNoPerms = testing;</div><div class="line"></div><div class="line">    <span class="comment">/*</span></div><div class="line">     * Only allow it to be set once, so after the content service gives</div><div class="line">     * this to us clients can't change it.</div><div class="line">     */</div><div class="line">    <span class="keyword">if</span> (mContext == <span class="keyword">null</span>) &#123;</div><div class="line">        mContext = context;</div><div class="line">        <span class="keyword">if</span> (context != <span class="keyword">null</span>) &#123;</div><div class="line">            mTransport.mAppOpsManager = (AppOpsManager) context.getSystemService(</div><div class="line">                    Context.APP_OPS_SERVICE);</div><div class="line">        &#125;</div><div class="line">        mMyUid = Process.myUid();</div><div class="line">        <span class="keyword">if</span> (info != <span class="keyword">null</span>) &#123;</div><div class="line">            setReadPermission(info.readPermission);</div><div class="line">            setWritePermission(info.writePermission);</div><div class="line">            setPathPermissions(info.pathPermissions);</div><div class="line">            mExported = info.exported;</div><div class="line">            mSingleUser = (info.flags &amp; ProviderInfo.FLAG_SINGLE_USER) != <span class="number">0</span>;</div><div class="line">            setAuthorities(info.authority);</div><div class="line">        &#125;</div><div class="line">        ContentProvider.<span class="keyword">this</span>.onCreate();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="最后是调用-Application-的-onCreate-方法"><a href="#最后是调用-Application-的-onCreate-方法" class="headerlink" title="最后是调用 Application 的 onCreate() 方法"></a>最后是调用 Application 的 onCreate() 方法</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">try</span> &#123;</div><div class="line">    mInstrumentation.callApplicationOnCreate(app);</div><div class="line">&#125; <span class="keyword">catch</span> (Exception e) &#123;</div><div class="line">    <span class="keyword">if</span> (!mInstrumentation.onException(app, e)) &#123;</div><div class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(</div><div class="line">            <span class="string">"Unable to create application "</span> + app.getClass().getName()</div><div class="line">            + <span class="string">": "</span> + e.toString(), e);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<blockquote>
<p>另外，在 <code>installProvider()</code> 方法中，用到的 provider 对象是 IContentProvider 类型，和 ContentProvider 对应，与 BroadcastReceiver Service 等相类似。因此 ContentProvider 的 crud 方法都是跨进程地工作。</p>
</blockquote>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag">#Android</a>
          
            <a href="/tags/Note/" rel="tag">#Note</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/09/02/BroadcastReceiverWorkProcess/" rel="next" title="BroadcastReceiver 的工作过程">
                <i class="fa fa-chevron-left"></i> BroadcastReceiver 的工作过程
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/10/05/jniNote/" rel="prev" title="jni 笔记">
                jni 笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://ww1.sinaimg.cn/mw690/6e8939a6gw1f3g1u1mc6lj20hs0hsmxf.jpg"
               alt="Granton Zhuang" />
          <p class="site-author-name" itemprop="name">Granton Zhuang</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives/index.html">
              <span class="site-state-item-count">26</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#方法入口"><span class="nav-number">1.</span> <span class="nav-text">方法入口</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#进程启动"><span class="nav-number">1.1.</span> <span class="nav-text">进程启动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ActivityThread-main"><span class="nav-number">1.2.</span> <span class="nav-text">ActivityThread#main()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ActivityThread-attach"><span class="nav-number">1.3.</span> <span class="nav-text">ActivityThread#attach()</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#handleBindApplication-方法的详情"><span class="nav-number">2.</span> <span class="nav-text">handleBindApplication() 方法的详情</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建-ContextImpl-和-Instrumention"><span class="nav-number">2.1.</span> <span class="nav-text">创建 ContextImpl 和 Instrumention</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#创建-Application"><span class="nav-number">2.2.</span> <span class="nav-text">创建 Application</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动当前进程的-ContentProvider-并且调用-onCreate-方法"><span class="nav-number">2.3.</span> <span class="nav-text">启动当前进程的 ContentProvider 并且调用 onCreate() 方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最后是调用-Application-的-onCreate-方法"><span class="nav-number">2.4.</span> <span class="nav-text">最后是调用 Application 的 onCreate() 方法</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Granton Zhuang</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  

  

  

</body>
</html>
